Introduction to R and RStudio

Set yourself up for success

Kim Cressman

kim@catbirdstats.com

2024-03-15

Intro

Who’s in the room

Goals in the room

Commonalities

No matter what you want to do, you need to get comfortable with a few basics first:

  • Getting data into R
  • Making sure your data frame looks right
  • Working with the data:
    • Taking a subset
    • Summarizing
    • Re-shaping
    • Connecting one data frame to another

Structure for today

Topics

  • Background and vocabulary
  • CODING - working with SWMP data
    • 2 nearly identical files
    • One has details; one is more of a skeleton
    • Follow along however you are most comfortable
    • Sticky notes - pink for “please come help me”; blue for “I successfully accomplished the task”
  • Moving forward

Remember

And sometimes

Tips

  • Be gentle with yourself
  • Be persistent
  • Help your neighbor
  • Look for commas and parentheses/brackets first - either missing or extra
  • Spelling and other punctuation next

Understanding code and context

File Types & getting meta about these slides

(so you can take notes in the R files that generated them, and render a complete document for yourself later)

  • .RProj - Project and how to open
  • .R - the basic “R script”
  • .Rmd - “RMarkdown”
  • .qmd - “Quarto”

Vocabulary

  • function
  • package
    • CRAN
    • GitHub
    • others
  • project
  • working directory and file paths
    • getwd()/setwd()
    • here::here()

RStudio IDE

  • global settings
  • panes
  • using the Environment pane to explore your workspace

Key “operators” in code

  • assignment operator: <-
  • pipe: |> or %>%
  • comments: #

Useful keyboard shortcuts

  • run a line of code: Ctrl/Cmd + Enter
  • make the assignment operator (<-): Alt + -
  • make a pipe (|>): Ctrl/Cmd + Shift + M
  • see more in RStudio’s ‘Tools’ menu; ‘Keyboard Shortcuts Help’